package com.zhentao.controller;

import com.zhentao.model.common.article.dto.ArticleHomeDto;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.service.ApArticleService;
import com.zhentao.service.FileStorageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.FileInputStream;

@RestController
@RequestMapping("/api/v1/article")
@Api(value = "测试minio接口")
public class ArticleContro {

@Autowired
private ApArticleService articleService;

@Autowired
private FileStorageService fileStorageService;

    @SneakyThrows
    @GetMapping("/testMinio")
    @ApiOperation(value = "测试上传文件",notes = "测试上传html文件")
    public ResponseResult testMinio() {
        FileInputStream fileInputStream = new FileInputStream("D:\\list.html");;
        String path=fileStorageService.uploadHtmlFile("article","list.html",fileInputStream);
        return ResponseResult.okResult(path);
    }

    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        return articleService.load(0, dto);
    }

    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        return articleService.load(1, dto);
    }

    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        return articleService.load(2, dto);
    }
}
